package com.yc.dygang;


import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Field;

import static java.lang.annotation.ElementType.*;


@DemoAnno(value = "demo2",nums = 19)
public class Demo2 {
    @DemoAnno(value = "小蜜瓜",nums = 1)
    public String name;

    @DemoAnno(value = "11" , age = "18",nums = {1,2})
    public void test(){

    }


    public static void main(String[] args) throws NoSuchFieldException {
        Field name = Demo2.class.getDeclaredField("name");
        DemoAnno annotation = name.getAnnotation(DemoAnno.class);
        System.out.println("annotation.value() = " + annotation.value());

        Demo3 demo3 = new Demo3();

        Class<? extends Demo3> aClass = demo3.getClass();
        DemoAnno annotation1 = aClass.getAnnotation(DemoAnno.class);
        System.out.println("annotation1.value() = " + annotation1.value());
    }
}

class Demo3 extends Demo2{}

@Target(
        value = {TYPE,
                 FIELD,
                 METHOD}
)
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@interface DemoAnno{
    String value();  //默认属性
    String age() default "1";
    int[] nums();
}
